/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * Nihongo
 * Copyright (C) Massimiliano Maniscalco 2011, 2012 <massi.neptune@yahoo.com>
 * 
 * Nihongo is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Nihongo is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "test_scelta_mult.h"

void TestSceltaMult::
init_test_scelta_mult ( Glib::RefPtr<Gtk::Builder> _bldr )
{
	init_test_engine ( _bldr );
	_bldr->get_widget ( "testSceltaMultipla", _testWin );
	// main
	_bldr->get_widget ( "testScMulDomLabel", _domandaLabel );
	_bldr->get_widget ( "testScMulRispButton1", _primaRispButton );
	_bldr->get_widget ( "testScMulRispButton2", _secondaRispButton );
	_bldr->get_widget ( "testScMulRispButton3", _terzaRispButton );
	_bldr->get_widget ( "testScMulRispButton4", _quartaRispButton );
	_rispostaBuona = -1;
	_rispostaEsatta = "";
}

void TestSceltaMult::
connect_signals ( void )
{
	connect_toolbar_signals ();
	_primaRispConnection = _primaRispButton->signal_clicked ().connect (sigc::bind<char>(sigc::mem_fun (*this, &TestSceltaMult::on_risposta), 0) );
	_secondaRispConnection = _secondaRispButton->signal_clicked ().connect (sigc::bind<char>(sigc::mem_fun (*this, &TestSceltaMult::on_risposta), 1) );
	_terzaRispConnection = _terzaRispButton->signal_clicked ().connect (sigc::bind<char>(sigc::mem_fun (*this, &TestSceltaMult::on_risposta), 2) );
	_quartaRispConnection = _quartaRispButton->signal_clicked ().connect (sigc::bind<char>(sigc::mem_fun (*this, &TestSceltaMult::on_risposta), 3) );
}

void TestSceltaMult::
pause_test ( void )
{
	_paused = true;
	_pauseToolButton->set_stock_id ( Gtk::StockID("gtk-media-play") );
	_timerConnection.disconnect ();
	_domandaLabel->set_visible ( false );
	_primaRispButton->set_visible ( false );
	_secondaRispButton->set_visible ( false );
	_terzaRispButton->set_visible ( false );
	_quartaRispButton->set_visible ( false );
}

void TestSceltaMult::
continue_test ( void )
{
	_paused = false;
	_pauseToolButton->set_stock_id ( Gtk::StockID("gtk-media-pause") );
	_domandaLabel->set_visible ( true );
	_primaRispButton->set_visible ( true );
	_secondaRispButton->set_visible ( true );
	_terzaRispButton->set_visible ( true );
	_quartaRispButton->set_visible ( true );
}

void TestSceltaMult::
on_window_closed ( void )
{
	_testWinConnection.disconnect ();
	_skipToolConnection.disconnect ();
	_pauseToolConnection.disconnect ();
	_primaRispConnection.disconnect ();
	_secondaRispConnection.disconnect ();
	_terzaRispConnection.disconnect ();
	_quartaRispConnection.disconnect ();
	_timerConnection.disconnect ();
	if ( _paused )
		continue_test ();
	if ( !show_result () )
		window_closed.emit ();
}

void TestSceltaMult::
on_result_window_closed ( void )
{
	_resultCtrlConnection.disconnect ();
	window_closed.emit ();
}
